package com.sloth.bear.dto.base;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sloth.bear.util.BaseHelper;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liufq
 * @since 2025-09-27 11-04-13
 */
@Data
public class ResponsePage<T> {

    private long current;

    private long size;

    private long total;

    protected List<T> records;

    public static <T> ResponsePage<T> ok() {
        ResponsePage<T> page = new ResponsePage<>();
        page.setRecords(new ArrayList<>());
        return page;
    }

    public static <T> ResponsePage<T> ok(Page<?> page, Class<T> clazz) {
        ResponsePage<T> responsePage = new ResponsePage<>();
        responsePage.setCurrent(page.getCurrent());
        responsePage.setSize(page.getSize());
        responsePage.setTotal(page.getTotal());
        responsePage.setRecords(BaseHelper.r2t(page.getRecords(), clazz));
        return responsePage;
    }

    public static <T> ResponsePage<T> ok(Page<?> page, List<T> records) {
        ResponsePage<T> responsePage = new ResponsePage<>();
        responsePage.setCurrent(page.getCurrent());
        responsePage.setSize(page.getSize());
        responsePage.setTotal(page.getTotal());
        responsePage.setRecords(records);
        return responsePage;
    }
}
